<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单项数据流</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
        <h3>父组件中使用了count</h3>
        <p>{{count}}</p>
        <custom-component :count="count" @increment-click="countHandle"></custom-component>
    </div>
    <script>
        Vue.component('custom-component',{
            props:['count'],
            data(){
                return {
                    incrementCount:this.count  
                } 
            },
            computed:{
                incrementCount2(){
                    return this.incrementCount
                }
            },
            template:`
                <div>
                    <h2>我是一个自定义的组件</h2>
                    <input type="button" value="改变count的值" @click="changeCount" />
                    {{incrementCount2}}
                </div>
            `,
            methods:{
                changeCount(){
                    this.incrementCount++;
                    this.$emit("increment-click")	
                }
            }
        })

        new Vue({
            el:"#app",
            data:{
                count:0
            },
            methods:{
                countHandle(){
                    this.count++;
                }
            }
        })
    </script>
</body>
</html>